package by.grsu.hdm.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import by.grsu.hdm.devices.MediaCenter;
import by.grsu.hdm.model.Audio;
import by.grsu.hdm.model.Video;

public class HelperMPS extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public HelperMPS() {
		super();

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html; charset=UTF-8");
		MediaCenter media = new MediaCenter("MED@$$@");
		String s = request.getParameter("group1");
		String ss =(String) request.getParameter("group2");
		if ("Play".equals(s)) {
			for (Video comp : media.contactMediaPlayer().videoList) {
				if (comp.name.equals(ss)) {
					media.contactMediaPlayer().remote.play(comp, response, ss);

				}
			}
			for (Audio comp : media.contactMediaPlayer().audioList) {
				if (comp.name.equals(ss)) {
					media.contactMediaPlayer().remote.play(comp, response, ss);

				}

			}
		}
		if ("Stop".equals(s)) {
			for (Video comp : media.contactMediaPlayer().videoList) {
				if (comp.name.equals(ss)) {
					media.contactMediaPlayer().remote.stop(comp, response, ss);

				}
			}
			for (Audio comp : media.contactMediaPlayer().audioList) {
				if (comp.name.equals(ss)) {
					media.contactMediaPlayer().remote.stop(comp, response, ss);

				}

			}
		}

		if ("Pause".equals(s)) {
			for (Video comp : media.contactMediaPlayer().videoList) {
				if (comp.name.equals(ss)) {
					media.contactMediaPlayer().remote.pause(comp, response, ss);

				}
			}
			for (Audio comp : media.contactMediaPlayer().audioList) {
				if (comp.name.equals(ss)) {
					media.contactMediaPlayer().remote.pause(comp, response, ss);

				}

			}
		}

	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
